<?php
	//includes
	require_once 'includes.php';

	//delete all
//	DB::ExecuteSQL("
//		DELETE FROM t_products;
//	");
	
	$startTime = microtime() + time();
	
	$yandexMarket = new YandexMarket();
	$products = $yandexMarket->GetSavedURLs($_GET['from'], $_GET['quantity']);
	
	$result = array('success' => 0, 'fail' => 0);
	
	//saves products
	foreach ($products as $key => $url)
	{
		//product item
		$productItem = $yandexMarket->GetProductItem($url['product_url_url']);
		$productItem->urlId = $url['product_url_id'];
		
		if (empty($productItem->modelPage))
		{
			echo "Banned on record #$key!";
			break;
		}

		//saves the product into DB
		$saveResult = $productItem->Save();
		
		//stats
		if ($saveResult)
		{
			$result['success']++;
		}
		else 
		{
			$result['fail']++;
		}		
	}

	$endTime = microtime() + time();
	
	//totals
	$resultTime = $endTime - $startTime;
	echo "Total time: $resultTime; Success: {$result['success']}; Fail: {$result['fail']}; ";		
	
?>